package com.example.demo_1106.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo_1106.entity.UserAddress;
import com.example.demo_1106.service.UserAddressService;
import com.example.demo_1106.mapper.UserAddressMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author kongke
 * @description 针对表【user_address】的数据库操作Service实现
 * @createDate 2023-07-23 10:09:06
 */
@Service
public class UserAddressServiceImpl extends ServiceImpl<UserAddressMapper, UserAddress>
        implements UserAddressService {

    @Autowired
    UserAddressMapper userAddressMapper;

    /**
     * 删除用户地址
     *
     * @param mobile 手机号
     * @return boolean
     */
    @Override
    public boolean delUserAddress(String mobile) {
        int del = userAddressMapper.delete(new QueryWrapper<UserAddress>().eq("tag", mobile));
        return del != 0;
    }

    /**
     * 查询用户地址
     *
     * @param mobile 手机号
     * @return {@link List}<{@link UserAddress}>
     */
    @Override
    public List<UserAddress> getAddress(String mobile) {
        List<UserAddress> addressesList;
        if ("".equals(mobile) || mobile == null) {
            addressesList = userAddressMapper.selectList(null);
        } else {
            addressesList = userAddressMapper.selectList(new QueryWrapper<UserAddress>().eq("mobile", mobile));
        }
        return addressesList;
    }

}




